<template>
	<view class="box">
		<div class="froms">
			<u-form :model="form" ref="uForm">
				<div class="boxs box1 u-flex">
					<u-form-item  label="客户" :error-type="errorType" label-width="240upx">
						<u-input v-model="customer_name" placeholder="客户姓名" />
					</u-form-item>
					<div class="pickers" @click="show = true">
					<!-- 	<u-picker mode="time" v-model="show"  default-time="2025-07-02 13:01"></u-picker>
						<u-picker mode="region" v-model="show"  :area-code='["13", "1303", "130304"]'></u-picker> -->
						<!-- 	<u-picker :params="params" v-model="show" mode="selector" :range="list" range-key="user_name" 
						 :default-selector="[0]"
						
						>
						
						</u-picker> -->
						<picker mode="selector" :range="list"  range-key="true_name" @change="bindPickerChange" :value="index">
							<view v-if="iswhow">{{list[index].true_name}} id{{list[index].id}} </view>
						</picker>
					</div>
				</div>
				<div class="boxs u-flex">
					<u-form-item  label="店铺名称" :error-type="errorType" label-width="240upx">
						<u-input v-model="shop_name" placeholder="请输入店铺名称" />
					</u-form-item>
				</div>
				<div class="boxs u-flex ">
					<u-form-item  label="店铺描述" :error-type="errorType" label-width="240upx">
						<u-input v-model="shop_describe"  placeholder="请输入店铺描述" />
					</u-form-item>
				</div>
				<div class="up">
					<u-form-item  label="店铺照片" :label-position="auto-upload" :error-type="errorType" label-width="500upx">
						<u-upload ref="uUpload" :action="action" :file-list="fileList" :auto-upload="true" :max-count="1" :header="header"
						 :name="name" @on-uploaded="onUploaded" :before-upload="beforeUpload" size-type="compressed"></u-upload>
					</u-form-item>
				</div>
			</u-form>
		</div>
		<div class="buttons">
			<u-button @click="go()" class="baocun">保存</u-button>
		</div>
				<u-toast ref="uToast" />

	</view>


</template>

<script>
	export default {
		data() {
			return {
				iswhow:true,
				defaultSelector: [0],
				params: {
					user_name:true
								},
				shop_name: " ",
				shop_describe: " ",
				shop_urls: " ",
				action: " ",
				show: false,
				errorType: ['none'],
				names: "",
				fileList: [],
				header: {
					"token": token
				},
				token:"",
				name: "img",
				showimg: "",
				index: 0,
				form: {
					name: '',
					shop: '',
					text: ""
				},
				rules: {
					name: [{
						required: true,
						message: '',
						trigger: ['blur', 'change']
					}]
				},
				list1: [
									{
										value: '1',
										label: '江'
									},
									{
										value: '2',
										label: '湖'
									}
								],
				list:[],
				radio: '',
				switchVal: false,
				userid:""
			};
		},
		onLoad() {
			this.gettoken()
			// this.getkehu()
			this.gokehulist()
			this.uUpload = this.$refs.uUpload
			this.action = this.$url + "/index.php/api/v1.Tool/uploadFlie"
		},
		methods: {
			gettoken(){
				wx.getStorage({
				  key: 'token',
				  success (res) {
				    console.log(res.data)
					this.token=res.data
				  }
				})
			},
			 bindPickerChange: function(e) {
			            console.log('picker发送选择改变，携带值为', e.target.value)
			            this.index = e.target.value
						console.log(this.list[e.target.value].id)
						this.userid=this.list[e.target.value].id
			        },
			onUploaded(lists) {
				this.filesArr = lists;
				console.log(this.$url + lists[0].response.url)
				// console.log(this.filesArr.url);

				this.shop_urls = this.$url + lists[0].response.url
				console.log(this.shop_urls);
				// console.log(this.filesArr[0].url)
				// console.log(this.filesArr)
			},
			beforeUpload(index, list) {
				if (index % 2 == 0) return true;
				else return false;
			},
			changename: function(e) {
				console.log("正在改变")
				this.index = e.target.value
				console.log(e.target.value)
			},
			go() {
				var that = this
				console.log(that.shop_name);
				console.log(that.shop_urls);
				console.log(that.shop_describe);
					if (that.userid!="") {
						wx.request({
							url: that.$url + '/api/v1.Shop/shopAdd', //仅为示例，并非真实的接口地址
							method: 'POST',
							data: {
								customer_id: that.userid,
								shop_name: that.shop_name,
								shop_urls: that.shop_urls,
								shop_describe: that.shop_describe
							},
							header: {
								token: that.$tok, // 默认值
							},
							success(res) {
								
								console.log(res.data.msg)
								if(res.data.msg=="添加成功"){
									that.goseccess()
									console.log("店铺添加成功")
								}
								else{
									that.gofail(res.data.msg)
								}
								
							},
							fail() {
							
							}
						})
					}
			},
			goseccess(){
					this.$refs.uToast.show({
									title: '店铺添加成功',
									type: 'success',
									url: '/pages/user/shopadmin'
								})
			},
			gofail(x){
				this.$refs.uToast.show({
					title: x,
					type: 'warning',
					// url: '/pages/user/index'
				})
			},
			gokehulist() {
				console.log("客户列表获取")
				let that = this
				wx.getStorage({
				  key: 'agent_id',
				  success (res) {
				    console.log("agent_id是")
				    console.log(res.data)
				    if(agent_id){
				    	wx.request({
				    		url: that.$url + '/index.php/api/v1.Customer/CustomerList', //仅为示例，并非真实的接口地址
				    		data: {
				    			agent_id:res.data,
				    			limit: 10,
				    			page: 1
				    		},
				    		header: {
				    			token: that.$tok // 默认值
				    		},
				    		success(res) {
				    			console.log("发送成功")
				    			console.log(res.data.data)
				    			// that.cusomerlist=
				    			that.list=res.data.data
				    			
				    		},
				    		fail(e) {
				    		}
				    	})
				    }
				  }
				})
				
					var agent_id = wx.getStorage('agent_id')
					// 删除
					
				
				
			
			},
			getkehu() {
				var that = this
				wx.getStorage({
					key: 'agent_id',
					success(res) {
						console.log(res.data)
						wx.request({
							url: that.$url + '/index.php/api/v1.Customer/CustomerList', //仅为示例，并非真实的接口地址
							method: 'GET',
							data: {
								page: 1,
								limit: 10,
								agent_id: res.data
							},
							success(res) {
								console.log("店铺添加成功")
								console.log(res)
							},
							fail() {
								console.log("发送失败")
							}
						})
					}
				})

			},
			// search(){
			// 	console.log("调用了方法")
			// 	var that=this
			// 	console.log(that.$tok)
			// 	let arr=[]
			// 	wx.request({
			// 	     url: this.$url+'/api/v1.Customer/selectWxUser', //仅为示例，并非真实的接口地址
			// 	     data: {
			// 	     		name:that.customer_name
			// 	     },
			// 	      header: {
			// 	          token:that.$tok // 默认值
			// 	        },
			// 	      success(res){
			// 	        console.log("搜索客户成功")
			// 			console.log(res)
			// 			// console.log(res.data.data)
			// 			// arr=res.data.data
			// 			// that.lists=arr
			// 			// that.list=arr[0]
			// 			// console.log(that.lists)
			// 			// arr=that.lists
			// 			// console.log("客户的临时数据"+arr[0])
			// 			// console.log("获得的id为"+arr)
			// 			// that.id=res.data.data[0].id
			// 	      },
			// 	      fail(ref){
			// 	       console.log("发送失败")
			// 		   console.log(ref)
			// 	      }
			// 	    })
			// }
		}
	}
</script>

<style scoped lang="scss">
	label {
		color: red;
	}

	.buttons /deep/ .u-button {
		background: red;
		border: none;
		color: red;
	}

	.slot-btn {
		width: 341rpx;
		height: 140rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: rgb(244, 245, 246);
		border-radius: 10rpx;
	}

	.u-form-item {
		margin: 0;
		padding: 0;
		// background-color: green;
	}

	.slot-btn__hover {
		background-color: green;
	}

	.zhengjian {}

	.up {
		// overflow: hidden;
		// background-color: green;
		height: 118upx;
		line-height: 118upx;
	}


	.box {
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		// height: 1000rpx;
		
		.froms {
			height: 1100upx;
			// border: 1px solid green;

		}

		// background-color: red;
		.boxs {
			
			// background-color: green;
			// border-bottom: 1px $gary solid;
			// height: 118upx;
		}

		.box1 {
			height: 131upx;
			// background-color: green;
			display: flex;
			flex-direction: row;
			justify-content: space-between;

			.pickers {
				// margin-right: 172rpx;
				width: 172rpx;
				height: 100%;
				border: none;
				overflow: hidden;
				// border: 1px solid red;
				display: flex;
				justify-content: center;
				align-items: center;
				// background-color: $red;
				.pike {
					background-color: red;
				}
				// background-color: red;
				background-image: url(../../static/icons/xiala.png);
				background-size: 40rpx;
				background-position: 100% center; 
				background-repeat: no-repeat;
			}


		}

		height: 100%;
		margin-left: 19upx;
		margin-right: 14upx;


		.buttons {
			width: 100%;
			height: 145upx;
			margin: 40rpx 0;

			// padding-bottom: 57upx;
			.baocun {
				// background-color: $red;
				// color: $f;
			}
		}
	}
</style>
